<template>
  <div class="login-Container">
    <!-- 头部 -->
    <div class="header">
      <div class="headerContainer">
        <div class="left">
          <a href="javascript:;"></a>
        </div>
        <div class="right"></div>
      </div>
    </div>
    <!-- 主体 -->
    <div class="body">
      <div class="center">
        <!-- 账号登录 -->
        <div class="login">
          <div class="top">
            <div class="top-left">会员注册</div>
            <div class="top-right active">
              已注册可
              <router-link to="/login" class="tologin">直接登录</router-link>
            </div>
          </div>
          <!-- 账号密码登录 -->
          <div class="login-center">
            <div class="center-from">
              <div class="phone">
                <input
                  placeholder="请输入你的手机号"
                  v-model="phone"
                  name="phone"
                  v-validate="{ required: true, regex: /^1[3-9]\d{9}$/ }"
                  :class="{ invalid: errors.has('phone') }"
                />
                <span></span>
              </div>
              <p class="error-msg">{{ errors.first("phone") }}</p>
              <div class="tips">
                <i class="iconfont icontishi1"></i>
                请先输入手机号安全验证
              </div>
              <div class="password">
                <input
                  placeholder="请输入你的登录密码"
                  v-model="password"
                  name="password"
                  v-validate="{ required: true, regex: /^.{6,20}$/ }"
                  :class="{ invalid: errors.has('password') }"
                />
                <span></span>
                <p class="error-msg">{{ errors.first("password") }}</p>
                <!-- <input
                  type="password"
                  placeholder="密码由8-20位字母,数字和符号组合"
                  v-model="password1"
                />
                <p v-if="!password1">密码不能为空</p> -->
              </div>
              <div class="password2">
                <input
                  placeholder="请输入确认密码"
                  v-model="password2"
                  name="password2"
                  v-validate="{ required: true, is: password }"
                  :class="{ invalid: errors.has('password2') }"
                />
                <span></span>
                <p class="error-msg">{{ errors.first("password2") }}</p>
                <!-- <input
                  type="password"
                  placeholder="请再次输入上面的密码"
                  v-model="password2"
                />
                <span></span>
                <p v-if="!password2">密码不能为空</p> -->
              </div>
              <div class="group">
                <input type="checkbox" v-model="isChecked" />
                <label for="">
                  我已阅读并接受以下条款：<a href="##">《唯品会服务条款》</a
                  ><a href="##">《隐私条款》</a
                  ><a href="##">《唯品支付用户服务协议》</a>
                </label>
                <!-- <p v-if="!isChecked">接收服务条款才能注册</p> -->
                <p class="error-msg">{{ errors.first("isChecked") }}</p>
              </div>
              <button class="item-login" @click="register">立即注册</button>
            </div>
          </div>
        </div>
        <!-- 扫码登录 -->
        <div></div>
      </div>
    </div>
    <!-- 底部 -->
    <div class="footer">
      <p>
        Copyright 2008-2020 vip.com，All Rights Reserved ICP证：粤 B2-20080329
      </p>
    </div>
  </div>
</template>

<script>
import request from "@/api/request";
export default {
  name: "Login",
  data() {
    return {
      phone: "",
      password: "",
      password2: "",
      isChecked: false
    };
  },
  methods: {
    async register() {
      // 需要整体验证通过才能去发请求
      const success = await this.$validator.validateAll();
      if (success) {
        let { phone, password, code, password2 } = this;
        const result = await request("/user/passport/register", {
          phone,
          password
        });
        if (result.code === 200) {
          alert("注册成功");
        } else {
          alert("注册失败");
        }
        // try {
        //   await this.$store.dispatch("userRegister", { phone, password, code });
        //   alert("用户注册成功，准备自动跳转到登录页");
        //   this.$router.push("/login");
        // } catch (error) {
        //   alert("用户注册失败");
        // }
      }
    }
  }
};
</script>

<style lang="less" scoped>
.login-Container {
  // 头部
  .header {
    width: 100%;
    height: 100px;
    .headerContainer {
      width: 1000px;
      height: 100px;
      margin: 0 auto;
      .left {
        float: left;
        a {
          display: block;
          width: 125px;
          height: 100px;
          background-image: url(../../assets/images/a.png);
          background-position: -308px -57px;
        }
      }
      .right {
        float: right;
        width: 304px;
        height: 100px;
        background-image: url(../../assets/images/a.png);
        background-position: 0 0;
      }
    }
  }
  // 主体
  .body {
    width: 100%;
    height: 650px;
    background-image: url(../../assets/images/1621046087806.jpg);
    background-position-x: -9px;
    .center {
      width: 1000px;
      height: 550px;
      margin: 0 auto;
      padding: 50px 20px;
      .login {
        width: 360px;
        height: 478px;
        float: right;
        background-color: #fff;
        .top {
          position: relative;
          width: 300px;
          height: 50px;
          line-height: 50px;
          padding: 0 30px;
          border-bottom: 1px solid #e0e0e0;
          .top-left {
            font-size: 18px;
            display: inline-block;
            height: 50px;
            text-align: center;
            line-height: 50px;
            font-weight: 700;
            color: #666;
            cursor: pointer;
          }
          .top-right {
            float: right;
            height: 50px;
            text-align: center;
            line-height: 50px;
            font-size: 14px;
            color: #666;
            cursor: pointer;
            .tologin {
              color: #f10180;
            }
          }
        }
        .login-center {
          width: 360px;
          height: 291px;
          .center-from {
            font-size: 14px;
            width: 300px;
            height: 271px;
            margin: 0 auto;
            .phone {
              position: relative;
              width: 300px;
              height: 46px;
              margin: 30px 0 10px 0;

              input {
                width: 248px;
                height: 32px;
                line-height: 32px;
                padding: 6px 10px 6px 40px;
                border: 1px solid #b2b2b2;
                border-radius: 3px;
                color: #333;
              }
              span {
                position: absolute;
                width: 20px;
                height: 20px;
                background-image: url(../../assets/images/a.png);
                background-position: -456px -221px;
                top: 13px;
                left: 11px;
              }
            }
            p {
              color: #ec5042;
              font-size: 12px;
              margin: 5px 0;
            }
            .tips {
              position: relative;
              width: 283px;
              height: 30px;
              line-height: 30px;
              margin-bottom: 19px;
              background-color: #dff1f8;
              border: 1px solid #b4e1f3;
              padding-left: 15px;
              i {
                font-size: 17px;
                font-weight: 700;
                color: #249fdf;
                margin-right: 13px;
              }
            }
            .password {
              position: relative;
              width: 300px;
              height: 46px;
              margin: 26px 0 19px 0;
              input {
                width: 248px;
                height: 32px;
                line-height: 32px;
                padding: 6px 10px 6px 40px;
                border: 1px solid #b2b2b2;
                border-radius: 3px;
                color: #333;
              }
              span {
                position: absolute;
                width: 20px;
                height: 20px;
                background-image: url(../../assets/images/a.png);
                background-position: -528px -221px;
                top: 13px;
                left: 11px;
              }
              p {
                color: #ec5042;
                font-size: 12px;
                margin-top: 3px;
              }
            }
            .password2 {
              position: relative;
              width: 300px;
              height: 46px;
              margin: 26px 0 19px 0;
              input {
                width: 248px;
                height: 32px;
                line-height: 32px;
                padding: 6px 10px 6px 40px;
                border: 1px solid #b2b2b2;
                border-radius: 3px;
                color: #333;
              }
              span {
                position: absolute;
                width: 20px;
                height: 20px;
                background-image: url(../../assets/images/a.png);
                background-position: -528px -221px;
                top: 13px;
                left: 11px;
              }
              p {
                color: #ec5042;
                font-size: 12px;
                margin-top: 3px;
              }
            }
            .group {
              width: 300px;
              height: 36px;
              font-size: 12px;
              margin: 5px 0;
              label {
                a {
                  color: #1d94d1;
                }
              }
              p {
                color: #ec5042;
                font-size: 12px;
                margin-top: 3px;
              }
            }
            .other {
              margin-top: 24px;
              height: 19px;
              width: 300px;
              .left {
                float: left;
                font-size: 14px;
              }
              .right {
                float: right;
              }
            }
            .item-login {
              display: block;
              width: 298px;
              height: 44px;
              line-height: 44px;
              margin-top: 24px;
              line-height: 46px;
              text-align: center;
              color: #fff;
              background-color: #f10180;
              border: 1px solid #f10180;
              border-radius: 3px;
              font-size: 18px;
              cursor: pointer;
            }
          }
        }
      }
    }
  }
  .footer {
    width: 1000px;
    height: 78px;
    line-height: 78px;
    margin: 0 auto;
    p {
      text-align: center;
      color: #666;
    }
  }
}
</style>
